﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WISD.CarFriend.BLL.OA;

namespace WISD.CarFriend.Web.Admin.OA.ShopManage
{
    public partial class ShopEdit : Utility.BasicPage
    {
        #region 字段
        private ShopModule m_ShopModuleBLL = new ShopModule();
        private int m_ShopId;
        #endregion


        #region 事件
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null || !int.TryParse(Request.QueryString["id"], out this.m_ShopId))
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }

            if (!IsPostBack)
            {
                // 验证权限
                base.CheckPermission("ShopManage_Edit");

                WISD.CarFriend.Model.CFModel.T_CF_OA_Shop shopModel
                    = this.m_ShopModuleBLL.GetModel(this.m_ShopId);
                if (shopModel != null)
                {
                    this.txtShopName.Text = shopModel.ShopName;
                    this.txtAddress.Text = shopModel.Address;
                    this.txtLeader.Text = shopModel.Leader;
                    this.txtPhone.Text = shopModel.Phone;
                    this.txtMobile.Text = shopModel.Mobile;
                }
                else
                {
                    base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                }
            }
        }


        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                WISD.CarFriend.Model.CFModel.T_CF_OA_Shop shopModel
                     = this.m_ShopModuleBLL.GetModel(this.m_ShopId);
                if (shopModel != null)
                {
                    shopModel.ShopName = this.txtShopName.Text.Trim();
                    shopModel.Address = this.txtAddress.Text.Trim();
                    shopModel.Leader = this.txtLeader.Text.Trim();
                    shopModel.Phone = this.txtPhone.Text.Trim();
                    shopModel.Mobile = this.txtMobile.Text.Trim();
                    this.m_ShopModuleBLL.Update(shopModel);
                    ShowMessageBox("修改成功！", "ShopList.aspx", "Success");
                }
            }
            catch (Exception ex)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + ex.Message.ToString(), "back", "Error");
            }
        }
        #endregion
    }
}